class FirstPage extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            list:[],
            thumburl: '',
            name: '',
            id: '0',
            partcount: 1,
            parts: [{src:''  }, {src:''  }, {src:'' }],
            categorylist: [],
            select_swiperlink:{name:'请选择'},
            swiperimglist: [],
            category_select_list: [],
            recommendtablehtml: [],
            recommendlist: [],
            goods_select_html: [],
            currentswipertype:0,
            swiperlinkhtml:[],
            swipertablehtml:[],
            swiperimghtml:[],
            swiper:{
                imgs:[],
                links:[]
            },
            entity:{
                name:"",
                id:''
            },
            fileimgshow:!0,
            imgstate:'',
            imgsrc:'',
            to:'',
        };
    }




    componentDidMount() {
            
    //    let cid = GetQueryString('id')
    //    this.setState({cid},()=>{
    //     this.freshlist()   
    //    })




            }
        freshlist(){
            dz_getsubcategorylist(this.state.cid,res=>{
               if(res.issuccess==1){
                this.setState({list:res.list,entity:res.entity||{name:"",
                id:''}})
              // this.formatlist(res.list);      
               console.log(res.list)
           }
        })

    }

 

/**新建 */
add(e) {
   var name = prompt('请输入二级分类名称');
   if(name!=''){
    aoedzsubcate({name,cid:this.state.cid},res=>{
        if(res.issuccess='1'){
            this.freshlist()  
        }
    })
   }
}


    // 编辑
    edit(x) {
        var name =prompt('请编辑分类名称',x.name)
        console.log(name,'namename');
        if(name!=null){
            aoedzsubcate({id:x.id,name,cid:this.state.cid},res=>{
                if(res.issuccess==1){
                    this.freshlist()
                }else{
                    alert(res.msg)
                }
            })
        }
       
       // 
    }

    
    tosub(e){
        window.location.href = "./dz_subcate.html?id="+e;
    }
    // 排序
    toorder(id) {
        let orders = prompt("请输入1-999的正整数"), { start } = this.state
        if (orders == "" || orders == null) {
            return;
        }
        if (isNaN(orders) || orders < 1 || orders > 999) {
            return;
        }
        orders = Math.floor(orders);
        Swipersetorders({ id, orders }, res => {
            if (res.issuccess == 1) {
                alert("设置成功");
                this.freshlist(start);
            }
        });
    }
    // // 上架下架
    // setshow(e, i, cid) {
    //     let { start } = this.state
    //     Goodssetstate({ id: e, cid }, res => {
    //         if (res.issuccess == 1) {
    //             alert(`${i == "0" ? '下架' : '上架'}成功`)
    //             this.freshlist(start)
    //         }
    //     })
    // }
    // 删除
    del(e, cid) {
        this.setState({ delid: e, newcid: cid }, () => {
            $('#myModal').modal('toggle');
        })
    }
    confirmdel() {
        let { delid,start } = this.state
        delimg( delid, res => {
            if (res.issuccess == 1) {
                alert('删除成功')
                $('#myModal').modal('toggle');
                this.freshlist(start)
            } else {
                $('#myModal').modal('toggle');
                alert(res.msg);
            }
        })
    }

    down(){
        const jsonData = [
            {
              name:'路人甲',
              phone:'123456789',
              email:'000@123456.com'
            },
            {
              name:'炮灰乙',
              phone:'123456789',
              email:'000@123456.com'
            },
            {
              name:'土匪丙',
              phone:'123456789',
              email:'000@123456.com'
            },
            {
            
            },
            {
                name:'流氓丁',
                phone:'123456789',
                email:'000@123456.com'
              },
          ]

          //列标题，逗号隔开，每一个逗号就是隔开一个单元格
      let str = `姓名,电话,邮箱\n`;
      //增加\t为了不让表格显示科学计数法或者其他格式
      for(let i = 0 ; i < jsonData.length ; i++ ){
        for(let item in jsonData[i]){
            str+=`${jsonData[i][item] + '\t'},`;     
        }
        str+='\n';
      }
      //encodeURIComponent解决中文乱码
      let uri = 'data:text/csv;charset=utf-8,\ufeff' + encodeURIComponent(str);
      //通过创建a标签实现
      let link = document.createElement("a");
      link.href = uri;
      //对下载的文件命名
      link.download =  "json数据表.csv";
      document.body.appendChild(link);
      link.click();
      document.body.removeChild(link);


      
    }



    render() {
        var { list,entity,select_swiperlink } = this.state;
        return (
            <div   className="breadLinebox">
            
                <p onClick={this.down.bind(this)}>点击下载</p>

            </div >
        )
    }
}





ReactDOM.render(
    <div>
        <TopLine />
        {/* <LeftMenu code='0' /> */}
        <LeftMenu code='dz_project' />
        <FirstPage />
    </div>
    //<Barrage/>
    , $('.container')[0]
)